﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeBehind="ControlPanel.aspx.cs"
    Inherits="CivilRegistry.ControlPanel" %>

<%@ Register Src="~/UserControls/UCUserGadget.ascx" TagName="UserGadget" TagPrefix="UC" %>
<%@ Register Src="~/UserControls/UCAddress.ascx" TagName="AddressControl" TagPrefix="UC" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="headerContent" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {
            $("#<%=pnlPermanentAddressEdit.ClientID%>").change(function () {
                $("#<%=pnlPermanentAddressEdit.ClientID%>").data("changed", true);
            });
        });

        function ValidatePermanentAddressEdit() {
            if ($("#<%=pnlPermanentAddressEdit.ClientID%>").data("changed")) {

                if ($("[id*='ucPermanentAddress_FlupldElectricitybill']").val() == "") {
                    $("[id*='ucPermanentAddress_lblValidation']").css('visibility', 'visible');
                    return false;
                }
            }

            if ($("[id*='ucPermanentAddress_txtAddress']").val() != "") {
                if ($("[id*='ucPermanentAddress_txtPIN']").val() == "") {
                    $("[id*='ucPermanentAddress_lblPinValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblPinValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPermanentAddress_txtCity']").val() == "") {
                    $("[id*='ucPermanentAddress_lblCityValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblCityValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPermanentAddress_ddlStateName']").val() == 0 || $("[id*='ucPermanentAddress_ddlStateName']").val() == null) {
                    $("[id*='ucPermanentAddress_lblStateValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblStateValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPermanentAddress_ddlDistrictName']").val() == 0 || $("[id*='ucPermanentAddress_ddlStateName']").val() == null) {
                    $("[id*='ucPermanentAddress_lblDistrictValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblDistrictValidation']").css('visibility', 'hidden');
            }
            return true;
        }
    </script>
</asp:Content>
<asp:Content ID="maincontent" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div class="mainContent">
            <asp:Panel ID="pnlTools" runat="server">
                <asp:Button ID="btnViewAll" runat="server" Text="View All" OnClick="btnViewAll_Click" CssClass="button greenButton medium" />
                <asp:Button ID="btnAddUser" Text="Add User" runat="server" OnClick="btnAddUser_Click" CssClass="button greenButton medium" />
            </asp:Panel>
            <asp:Panel ID="pnlViewAllUser" runat="server">
                <div class="form-content" style="float: left;">
                    <asp:GridView ID="gvUsers" runat="server" AllowPaging="true" AutoGenerateColumns="False"
                        CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                        EmptyDataText="No records found!" AllowSorting="true" OnSorting="gvUsers_Sorting"
                        OnPageIndexChanging="gvUsers_PageIndexChanging" OnRowCommand="gvUsers_RowCommand"
                        OnRowEditing="gvUsers_RowEditing" BorderWidth="2px">
                        <HeaderStyle VerticalAlign="Top" BackColor="#003366" ForeColor="White" />
                        <RowStyle BackColor="White" ForeColor="Black" />
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:HiddenField ID="hdnUserId" runat="server" Value='<%# Eval("UserId") %>' />
                                    <asp:HiddenField ID="hdnUserType" runat="server" Value='<%# Eval("UserType") %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="UserId" DataField="UserId" SortExpression="UserId" />
                            <asp:BoundField HeaderText="First Name" DataField="FirshtName" SortExpression="FirshtName" />
                            <asp:BoundField HeaderText="Middle Name" DataField="MiddleName" SortExpression="MiddleName" />
                            <asp:BoundField HeaderText="Last Name" DataField="LastName" SortExpression="LastName" />
                            <asp:BoundField HeaderText="User Type" DataField="UserType" SortExpression="UserType" />
                            <asp:TemplateField HeaderText="Action">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnEdit" CommandName="Edit" CommandArgument='<%# Container.DataItemIndex %>'
                                        runat="server">Edit</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </div>
            </asp:Panel>
            <center>
                <asp:Label ID="lblStatus" runat="server" BackColor="Yellow" ForeColor="DarkBlue"
                    Font-Bold="true"></asp:Label>
            </center>
            <asp:HiddenField ID="hdnUserId" runat="server" />
            <asp:HiddenField ID="hdnUserType" runat="server" />
            <asp:Panel ID="pnlDisplay" runat="server">
                <div class="form-content">
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblUserId" runat="server" Text="User Id:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblUserIdValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblUserName" runat="server" Text="User Name:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblUserNameValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblFirstName" runat="server" Text="First Name:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblFirstNameValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblMiddleName" runat="server" Text="Middle Name:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblMiddleNameValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblLastName" runat="server" Text="Last Name:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblLastNameValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblEmailAddress" runat="server" Text="Email Address:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblEmailAddressValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblPhoneNo" runat="server" Text="PhoneNo:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblPhoneNoValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblDateOfBirth" runat="server" Text="Date Of Birth:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblDateOfBirthValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblAddress" runat="server" Text="Address:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblAddressValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblPIN" runat="server" Text="PIN:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblPINValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblCity" runat="server" Text="City:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblCityValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblStateName" runat="server" Text="State:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblStateNameValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblDistrictName" runat="server" Text="District:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:Label ID="lblDistrictNameValue" runat="server"></asp:Label>
                        </div>
                    </div>
                    <div class="bottomButtons">
                        <asp:Button ID="btnEditUser" runat="server" Text="Edit" CssClass="button greenButton medium"
                            OnClick="btnEdit_Click" />
                    </div>
                </div>
            </asp:Panel>
            <asp:Panel ID="pnlEditUser" Visible="false" runat="server">
                <div class="form-content">
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblUserType" runat="server" Text="User Type:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:DropDownList ID="ddlUserType" runat="server">
                                <asp:ListItem Text="--Select--" Value="0"></asp:ListItem>
                                <asp:ListItem Text="Admin" Value="1"></asp:ListItem>
                                <asp:ListItem Text="Hospital" Value="2"></asp:ListItem>
                            </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ddlUserType"
                                CssClass="redText" ErrorMessage="Please select the User Type."></asp:RequiredFieldValidator>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblUserNameEdit" runat="server" Text="User Name:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblCPFirstNameEdit" runat="server" Text="First Name:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblCPMiddleNameEdit" runat="server" Text="Middle Name:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:TextBox ID="txtMiddleName" runat="server"></asp:TextBox>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblEmailaddressEdit" runat="server" Text="EmailAddress:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:TextBox ID="txtEmailAddress" runat="server"></asp:TextBox>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtEmailAddress"
                                CssClass="redText" Display="Static" ErrorMessage="Please enter valid email" Font-Size="Smaller"
                                Width="99px" Font-Bold="true" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                        </div>
                    </div>
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1">
                            <asp:Label ID="lblPhoneNoEdit" runat="server" Text="PhoneNo:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:TextBox ID="txtPhoneNo" runat="server"></asp:TextBox>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtPhoneNo"
                                CssClass="redText" Display="Static" ErrorMessage="Please enter valid phone no."
                                Font-Size="Smaller" Width="99px" Font-Bold="true" ValidationExpression="\d{10}"></asp:RegularExpressionValidator>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblDateofBirthEdit" runat="server" Text="Date of Birth"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:CalendarExtender ID="calendarExtdrDateOfBirth" TargetControlID="txtDateOfBirth"
                                    runat="server">
                                </asp:CalendarExtender>
                                <asp:TextBox ID="txtDateofBirth" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please enter the Date Of Birth"
                                    CssClass="redText" ControlToValidate="txtDateOfBirth"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                        <asp:Panel ID="pnlPermanentAddressEdit" runat="server">
                            <div style="font-size: large; font-weight: bold; height: 38px;">
                                Permanet Address:</div>
                            <UC:AddressControl ID="ucPermanentAddress" runat="server" />
                        </asp:Panel>
                        <div class="bottomButtons">
                            <asp:Button ID="btnSave" Text="Save" runat="server" OnClientClick="Page_ClientValidate(); return ValidatePermanentAddressEdit();"
                                OnClick="btnSave_Click" CssClass="button greenButton medium" />
                            <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="button red medium"
                                OnClick="btnCancel_Click" ValidationGroup="Different" />
                        </div>
                    </div>
                </div>
            </asp:Panel>
        </div>
        <div class="Gadget">
            <UC:UserGadget ID="UserGadget1" runat="server" />
        </div>
    </div>
</asp:Content>
